package br.com.cogerh.sidec.dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;

import br.com.cogerh.sidec.model.Historico;
import br.com.cogerh.sidec.model.LogEmail;
import br.com.cogerh.sidec.util.HibernateUtil;

public class LogEmailImpl implements LogEmailDAO{

	@Override
	public void salvar(LogEmail logEmail) {
		Session sessao = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction tx = sessao.beginTransaction();
		try {
			sessao.save(logEmail);
			sessao.flush();
			sessao.close();
			tx.commit();
		} catch (HibernateException e) {
			tx.rollback();
		}

		
	}

	@Override
	public List<LogEmail> listar() {
		Session sessao = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction tx = sessao.beginTransaction();
		List<LogEmail> lista = new ArrayList<LogEmail>();
		try{
			Criteria criteria = sessao.createCriteria(LogEmail.class);
			lista = criteria.list();
			sessao.close();
		}catch(HibernateException e){
			tx.rollback();
		}
	
		return lista;
	}

}
